// Copyright 2013 Google Inc. All Rights Reserved.auto

#include <errno.h>
#include <irt_syscalls.h>
#include <sys/socket.h>


int connect(int sockfd, const struct sockaddr *address, socklen_t  len) {
  ENOSYS_IF_NULL(__nacl_irt_connect)

  struct nacl_abi_sockaddr na_addr;
  size_t na_size;

  __sockaddr_to_nacl_abi_sockaddr(address, len, &na_addr, &na_size);

  int newfd;
  int result = __nacl_irt_connect(sockfd, &na_addr, na_size, &newfd);

  if (result != 0) {
    errno = __nacl_abi_errno_to_errno(result);
    return -1;
  }

  return newfd;
}

